class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode(int x) {
        val = x;
    }
}

public class isSymmetric {
    public boolean _isSymmetric(TreeNode root) {
        if (root == null)
            return true;
        return dfs(root.left, root.right);

    }

    boolean dfs(TreeNode A, TreeNode B) {
        // 终止条件
        if (A == null && B == null)
            return true;
        if (A == null || B == null)
            return false;
        if (A.val != B.val)
            return false;
        return dfs(A.left, B.right) && dfs(A.right, B.left);
    }
}
